<style scoped lang="sass">
    .w-e-toolbar {
        overflow: hidden;
    }
</style>
<template>
    <div>
        <div id="editor"></div>
    </div>
</template>
<script>
    import E from "wangeditor";
    export default {
        /*
                  **option参数**
                  @param content         内容                 String/DOM
                  
              */
        props: {
            content: {
                type: String,
                required: true
            }
        },
        data() {
            return {};
        },
        watch: {
            'content'(val){
                this.$emit('innnerhtml',val)
            }
        },
        created() { },
        mounted() {
            this.$nextTick(() => {
                var This = this;
                // 创建编辑器
                var editor = new E("#editor");
                // debug 模式
                editor.customConfig.onchange = html => {
                    // html 即编辑器中的内容
                    this.$emit("update:content", html);
                };
                // 配置编辑区域的 z - index
                editor.customConfig.zIndex = 100;
                // 上传图片到服务器
                // 限制一次最多上传 5 张图片
                editor.customConfig.uploadImgMaxLength = 1;
                editor.customConfig.uploadImgServer = config.baseApi + "bookMall-admin/api/common/fwbUpload";
                editor.customConfig.uploadFileName = "myfile";
                editor.customConfig.uploadImgHooks = {
                    customInsert: function (insertImg, result, editor) {
                        insertImg(result.data);
                    }
                };



                // 隐藏“网络图片”tab
                editor.customConfig.showLinkImg = false;

                editor.create();
                this.$once('innnerhtml', (content) =>{
                    editor.txt.html(content);
                })
            });
        },
        methods: {
        }
    };
</script>